﻿using UnityEngine;
using System.Collections;

public class SelfRegist : MonoBehaviour
{
	string user = string.Empty;
	string pwd = string.Empty;
	void OnGUI()
	{
		int cwidth = Screen.width / 2;
		int cheight = Screen.height / 2;
		var boxPos = new Rect(cwidth - 110, cheight - 160, 240, 120);

		GUI.Box(boxPos, "");
		GUI.Label(new Rect(cwidth - 100, cheight - 150, 100, 22), "User:");
		user = GUI.TextField(new Rect(cwidth - 10, cheight - 150, 120, 22), user, 20);
		GUI.Label(new Rect(cwidth - 100, cheight - 120, 100, 22), "Password:");
		pwd = GUI.PasswordField(new Rect(cwidth - 10, cheight - 120, 120, 22), pwd, '*', 20);

		if (GUI.Button(new Rect(cwidth - 100, cheight - 80, 80, 22), "Regist"))
		{
			Debug.LogError("**********手动注册");
			NetWriter.SetUrl("127.0.0.1:9700");
			Debug.LogError(user);
			Debug.LogError(pwd);
			GameSetting.Instance.Pid = user;
			GameSetting.Instance.Password = pwd;
			Net.Instance.Send((int)ActionType.SelfRegist, RegistCallback, null);
		}
	}

	//自定义注册之后服务器返回的用户名和密码
	private void RegistCallback(ActionResult actionResult)
	{
		Debug.LogError("自定义注册回调");
		if (actionResult != null)
		{
			user = actionResult.Get<string>("Name");
			pwd = actionResult.Get<string>("PWD");
			Debug.LogError(user);
			Debug.LogError(pwd);
		}
	}
}
